import request from '../utils/request';

/**
 * 新建用户角色
 * @param {string} name 角色名称
 * @param {string[]} guardUuidList 权限uuid列表
 */
export function createRoleApi(name, description, guardUuidList) {
  return request({
    url: '/roles',
    method: 'post',
    data: { name, description, guard_uuid_list: guardUuidList }
  });
}

/**
 * 删除用户角色
 * @param {string} uuid 角色uuid
 */
export function deleteRoleApi(uuid) {
  return request({
    url: '/roles/' + uuid,
    method: 'delete'
  });
}

/**
 * 修改角色权限列表
 * @param {string} uuid 角色uuid
 * @param {string[]} guardUuidList 权限uuid列表
 */
export function updateRoleGuardListApi(uuid, guardUuidList) {
  return request({
    url: '/roles/' + uuid + '/guards',
    method: 'patch',
    data: { guard_uuid_list: guardUuidList }
  });
}

/**
 * 修改角色名
 * @param {string} uuid 角色uuid
 * @param {string} name 角色名
 * @param {string} description 角色描述
 */
export function updateRoleApi(uuid, name, description) {
  return request({
    url: '/roles/' + uuid,
    method: 'patch',
    data: { name, description }
  });
}

// 获取用户角色列表
export function getRoleListApi() {
  return request({
    url: '/roles',
    method: 'get'
  });
}

/**
 * 移除用户角色
 * @param {string} userUuid 用户uuid
 * @param {string} roleUuid 角色uuid
 */
export function deleteUserRoleApi(userUuid, roleUuid) {
  return request({
    url: '/users/roles',
    method: 'delete',
    data: {
      user_uuid: userUuid,
      role_uuid: roleUuid
    }
  });
}
